package model

import "qabx.net/safe-app-center/pkg/utils"

type TblGatewayDeviceRel struct {
	DeviceId   int    `json:"device_id"`
	GatewayId  int    `json:"gateway_id"`
	IsDel      int    `json:"is_del"`
	IsOnline   int    `json:"is_online"`
	IsBlack    int    `json:"is_black"`
	UpdateTime string `json:"update_time"`
	CreateTime string `json:"create_time"`
}

type GatewayDevice struct {
	DeviceId   int    `json:"device_id"`
	GatewayId  int    `json:"gateway_id"`
	DeviceMac  string `json:"device_mac"`
	DeviceIp   string `json:"device_ip"`
	DeviceIpv6 string `json:"device_ipv6"`
	DeviceName string `json:"device_name"`
	IsOnline   int    `json:"is_online"`
}

// GetGatewayDeviceList 获取网关下所有设备信息
func GetGatewayDeviceList(gatewayId int) ([]*GatewayDevice, error) {
	res := []*GatewayDevice{}
	dbClient, _ := utils.GetDbClient()
	sql := "SELECT a.is_online, a.device_id,a.gateway_id,b.device_name,b.device_mac,b.device_ipv6 FROM  tbl_gateway_device_rel a,tbl_device b WHERE  a.device_id = b.device_id  AND a.gateway_id=? AND a.is_del=0 ORDER BY b.update_time"
	err := dbClient.Client.SQL(sql, gatewayId).Find(&res)
	return res, err
}
